package com.tc.travel.submitter.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.tc.travel.submitter.executor.ReturnReportAddOneByOneExecutor;
import com.tc.travel.submitter.executor.ReturnReportDownloadExecutor;
import com.tc.travel.submitter.executor.SessionMaintainerExecutor;
import com.tc.travel.submitter.executor.VisaAddUpdateExecutor;
import com.tc.travel.submitter.executor.VisaCancelExecutor;

/**
 * Created by Lenovo on 2017-08-22.
 */
@Component
public class JobEntry {
	@Autowired
	private VisaAddUpdateExecutor visaAddUpdateExecutor;

	@Autowired
	private VisaCancelExecutor visaCancelExecutor;

	@Autowired
	private ReturnReportAddOneByOneExecutor returnReportAddOneByOneExecutor;

	@Autowired
	private ReturnReportDownloadExecutor rturnReportDownloadExecutor;

	@Autowired
	private SessionMaintainerExecutor sessionMaintainerExecutor;

	// 所有操作都串行化，避免页面跳转失败
	// 同时，job用的cookie不能和浏览器用的cookie是同一个
	@Scheduled(cron = "0/1 * * * * ?")
	public void execute() {
		// // 刷新cookie
		// sessionMaintainerExecutor.execute();

		// 新增visa
		visaAddUpdateExecutor.execute();

		// 取消visa
		visaCancelExecutor.execute();

		// 导入归报
		returnReportAddOneByOneExecutor.execute();

		// 下载归报
		rturnReportDownloadExecutor.execute();
	}

	// // 撤消visa
	// @Scheduled(cron = "0/1 * * * * ?")
	// public void cancelVisa() {
	// visaCancelExecutor.execute();
	// }

	// // 导入归报
	// @Scheduled(cron = "0/1 * * * * ?")
	// public void importReturnReport() {
	// returnReportImportExecutor.execute();
	// }

	@Scheduled(cron = "0 0/5 * * * ?")
	public void refreshCookie() {
		sessionMaintainerExecutor.execute();
	}
}
